//
//  HWRechargeNotesViewController.m
//  嗨文
//
//  Created by 响当当 on 2019/2/15.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWRechargeNotesViewController.h"
#import "HWRechargeNoteView.h"

@interface HWRechargeNotesViewController ()
@property (nonatomic, strong)HWRechargeNoteView *rechargeNoteView;
@property (nonatomic, strong) NSMutableArray *yearArray;

@property (nonatomic, strong) NSMutableArray *monthArray;
@end

@implementation HWRechargeNotesViewController

- (HWRechargeNoteView *)rechargeNoteView
{
    if (!_rechargeNoteView)
    {
        _rechargeNoteView = [[HWRechargeNoteView alloc]initWithFrame:CGRectMake(0,NAVIBAR_HEIGHT,SCREEN_WIDTH,SCREEN_HEIGHT-NAVIBAR_HEIGHT)];
        WeakSelf(self)
        _rechargeNoteView.getYearAndMonthBlock = ^(NSString *year, NSString *month) {
            [weakSelf getInfor:year month:month];
        };
    }
    return _rechargeNoteView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self buryPoint:self.type];
    
    if ([self.type isEqualToString:@"0"])
    {
        [self setTitle:@"VIP充值记录"];
    }
    else
    {
        [self setTitle:@"消费记录"];
    }
    [self setDefaultNav];
    
    NSDate *newDate = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth;
    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:newDate];
    NSInteger year = [dateComponent year];
    NSInteger month = [dateComponent month];
    
    [self getInfor:[NSString stringWithFormat:@"%ld",year] month:[NSString stringWithFormat:@"%ld",month]];
    
    [self.view addSubview:self.rechargeNoteView];
}

#pragma mark - vip充值记录
- (void)getInfor:(NSString *)year month:(NSString *)month
{
    
    NSDictionary *prarmers = @{
                               @"access_token" : current_User.token,
                               @"month" : month,
                               @"year" : year
                               };
    
    if ([self.type isEqualToString:@"0"])
    {
        WeakSelf(self)
        [MyInfoManager setVipRechargeNote:prarmers sucess:^(id  _Nonnull acceptData) {
            [weakSelf.rechargeNoteView getRechargeNoteDate:acceptData[@"list"] Type:self.type];
        } fail:^(NSError * _Nullable error) {
            DISMISS_SVP(1.0f);
            [SVProgressHUD showErrorWithStatus:@"获取失败，请检查网络是否良好"];
            DISMISS_SVP(1.0f);
        }];
    }
    else
    {
        WeakSelf(self)
        [MyInfoManager setConsumeRecord:prarmers sucess:^(id  _Nonnull acceptData) {
            [weakSelf.rechargeNoteView getRechargeNoteDate:acceptData[@"list"] Type:self.type];
        } fail:^(NSError * _Nullable error) {
            DISMISS_SVP(1.0f);
            [SVProgressHUD showErrorWithStatus:@"获取失败，请检查网络是否良好"];
            DISMISS_SVP(1.0f);
        }];
    }
}


- (void)buryPoint:(NSString *)str
{
    NSString *lastStayTime = [kUserDefaults objectForKey:@"time"];
    NSString *nowStayTime = [NSString stringWithFormat:@"%ld",[[HWUtilties getNowTimeTimestamp3] integerValue] - lastStayTime.integerValue];
    
    if ([str isEqualToString:@"0"])
    {
        [HWUtilties buryPointWithStayTime:nowStayTime
                                timestamp:[HWUtilties getNowTimeTimestamp3]
                                 memberId:current_User.userID
                                  fromUrl:nil
                                    toUrl:@"/topUpRecord"
                                   fromId:nil
                                     toId:@"d501d94481391e68"];
    }
    else
    {
        [HWUtilties buryPointWithStayTime:nowStayTime
                                timestamp:[HWUtilties getNowTimeTimestamp3]
                                 memberId:current_User.userID
                                  fromUrl:nil
                                    toUrl:@"/topUpRecord"
                                   fromId:nil
                                     toId:@"afc20c073fcb7a03"];
    }
   
}
@end
